<script>
$(document).ready(function()
{
    <?php 
        if (isset($notify) && $notify != "")
        {
            if ($notify == "marque_not_found") {
                $type = "errorR";
                $title = "Thông báo";
                $text = "Không tìm thấy Thương hiệu";
                $icon = "picon icon16 brocco-icon-info white";
            } elseif ($notify == "order_not_found") {
                $type = "errorR";
                $title = "Thông báo";
                $text = "Không tìm thấy Đơn hàng mà bạn muốn xem sản phẩm.";
                $icon = "picon icon16 brocco-icon-info white";
            } 
            ?>
            $.pnotify({
                type: '<?=$type?>',
                title: '<?=$title?>',
                text: '<?=$text?>',
                icon: '<?=$icon?>',
                opacity: 0.9,
                history: false,
                sticker: false
            });
            <?
        }
    ?>
});
</script>
<?php if (isset($order_details)): ?>
<?php foreach ($order_details as $id => $detail) : ?>
<form method="POST" action="<?php echo url_for('@order_place') ?>">
<div class="row-fluid">
    <div class="span12">
        <div class="header">
            <h4><?php echo "Chi tiết đơn hàng của thương hiệu ".$detail['name'] ?></h4>
        </div>
        <table class="responsive table">
            <thead>
               <tr>
                    <th>
                        <span>ID</span>
                    </th>
                    <th>
                        <span>Tên</span>
                    </th>
                    <th>
                        <span>Tuỳ chọn</span>
                    </th>
                    <th>
                        <span>Số lượng</span>
                    </th>
                    <th>
                        <span>Tình trạng</span>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($detail['list'] as $item): ?>
                <tr>
                    <td style='text-align:center;'><?php echo $item['product_id'] ?></td>
                    <input type="hidden" class="product_order_<?php echo $id ?>" value="<?php echo $item['product_id'].';'.$item['option_id'] ?>">
                    <td style='text-align:center;'><?php echo $item['product_name'] ?></td>
                    <td style='text-align:center;'><?php echo $item['option_name'] ?></td>
                    <td style='text-align:center;'><?php echo $item['quantity'] ?></td>
                    <td style='text-align:center;'><?php echo OrderProduct::$status[$item['status']] ?></td>
                </tr>
                <?php endforeach ?>
            </tbody>
        </table>
    </div>
</div>
<input class="btn" type="button" value="Order" onclick="place_order(<?php echo $id ?>)">
</form>
<?php endforeach ?>
<?php endif ?>
<script>
    function place_order(marque_id) {
        product_list = new Array();
        $('.product_order_'+marque_id).each(function(){
            product_list.push($(this).val().split(";"));
        });
        $.post("<?php echo url_for('@order_place') ?>", { marque_id: marque_id, product_list: product_list, order_id: <?php echo $order_id ?> }, function (data) {
            alert(data);
        });
    }
</script>